<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Defect Tracking System - Edit Account</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.4.2/pure-min.css">
</head>
<body>

<center>
<br>
<div class="pure-g">
	<style scoped>
        .button-secondary {
            color: white;
            border-radius: 4px;
            text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
        }
        .button-secondary {
            background: rgb(66, 184, 221); /* this is a light blue */
        }

	</style>
	
    <div class="pure-u-1-3"> </div>
    <div class="pure-u-1-3">
    	<button class="button-secondary pure-button">Defect Tracking System</button> 
    </div>
    <div class="pure-u-1-3"> Team B </div>
</div>
<br><br>
<!------------------------------------------------->
<!-------------------head ----------------------->
<!------------------------------------------------->

<h3>Edit User Profile</h3>

<!------------------------------------------------->
<!------------------- create account form  ----------------------->
<!------------------------------------------------->
<%
	//Set Database info
	String DB_DRIVER_NAME = "com.mysql.jdbc.Driver";
	String DB_URL = "jdbc:mysql://localhost:3306/defect_tracker";
	String DB_USER = "root";
	String DB_PASSWORD = "root";
		
	//Load Driver
	try {
	    Class.forName(DB_DRIVER_NAME);
	}catch(ClassNotFoundException e) {
	    System.out.println("</br> can't find " + DB_DRIVER_NAME +" driver</br>");
	    e.printStackTrace();	    
	}
	
	Connection con = null; // defect table connection
	Statement stmt = null;
	ResultSet rs = null;
	
	request.getSession(true);
	Integer userID = (Integer)session.getAttribute("UserID");
	
	try {
		 String getUser = "select fname, lname, email, phone from user where UserID= " + userID;
		 //connect to database
	    con = DriverManager.getConnection(DB_URL,DB_USER,DB_PASSWORD);	    
	    //Create a Statement
	    stmt = con.createStatement();	    
	    //execute SQL
	    rs = stmt.executeQuery(getUser);
	    
	   	while(rs.next()) {
  		String	lastName = rs.getString(2);
  		String	firstName = rs.getString(1);
  		String	emailAddress = rs.getString(3);
  		String	phoneNumber = rs.getString(4); 
	   	
        
 %>       
<form class="pure-form pure-form-aligned" action="UpdateAccountServlet" method="post">
    <fieldset>
               <input type="hidden" name="userID" value="<%=userID%>">
        <div class="pure-control-group">
            <label class="pure-input-1-4">First Name</label>
            <input class="pure-input-1-4"  id="fname" type="text" name="fname" value="<%=firstName%>">
        </div>
        
        <div class="pure-control-group">
            <label class="pure-input-1-4">Last Name</label>
            <input class="pure-input-1-4"  id="lname" type="text" name="lname" value="<%=lastName%>">
        </div>
        
       <div class="pure-control-group">
            <label class="pure-input-1-4">Email Address</label>
            <input class="pure-input-1-4"  id="email" type="text" name="email" value="<%=emailAddress%>">
        </div>
        
        <div class="pure-control-group">
            <label class="pure-input-1-4"  for="phone">Phone Number</label>
            <input class="pure-input-1-4"  id="phone" type="text" name="phone" value="<%=phoneNumber%>">
        </div>        
		
		<br>
		<div class="pure-control-group">
            <button type="submit" class="pure-button pure-button-primary">Update</button>&nbsp;&nbsp;
            </div>
    </fieldset>
</form>
<%
	   	}
	} catch (SQLException se) {
		System.out.println("Message : " + se.getMessage() );
		 se.printStackTrace();	
	} finally {
		rs.close();
		stmt.close();
		con.close();
	}

%>
</body>
</html>